package day14;

import com.alibaba.fastjson2.JSON;
import day13.Product;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class JSoTest {
    public static void main(String[] args) {
//        List<Product> ps=new ArrayList<>();
//        ps.add(new Product(1,"核桃仁",55.5,100,false,"河北","袋"));
//        ps.add(new Product(2,"荣事达洗衣机",1555.5,3,false,"河北","台"));
//        ps.add(new Product(3,"格兰仕微波炉",455.2,22,false,"河北","台"));
//        ps.add(new Product(4,"中华牙膏",4.5,2222,false,"河北","袋"));
//        ps.add(new Product(5,"波司登羽绒服",1055.5,100,false,"河北","件"));
//        System.out.println(JSON.toJSONString(ps));
        try {
            FileInputStream fin=new FileInputStream("F:/1.json");
            byte []b=new byte[fin.available()];
            fin.read(b);
            String str=new String(b);
            fin.close();
            //System.out.println(str);
            //json string =>Object
            List<Product> p = JSON.parseArray(str, Product.class);
            for(Product product:p)
                System.out.println(product);
        } catch ( Exception e) {
            e.printStackTrace();
        }
    }
}
